package com.company.project.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.project.common.utils.DataResult;
import com.company.project.entity.ClassesEntity;
import com.company.project.entity.StudentEntity;
import com.company.project.service.ClassesService;
import com.company.project.service.StudentService;
import com.company.project.vo.resp.StudentVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * 学生信息表
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2025-06-24 15:07:28
 */
@Controller
@RequestMapping("/")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @Autowired
    private ClassesService classesService;

    @Autowired
    HttpServletRequest request;

    /**
    * 跳转到页面
    */
    @GetMapping("student/list")
    public String student() {
        Page<ClassesEntity> classesPage = classesService.page(new Page<>(1, 1000));
        request.setAttribute("classes", classesPage.getRecords());
        return "student/list";
    }


    @ApiOperation(value = "查询分页数据")
    @PostMapping("student/listByPage")
    @SaCheckPermission("student:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody StudentVo studentVo){
        IPage<StudentVo> iPage = studentService.pageInfo(studentVo);
        return DataResult.success(iPage);
    }


    @ApiOperation(value = "新增")
    @PostMapping("student/add")
    @SaCheckPermission("student:add")
    @ResponseBody
    public DataResult add(@RequestBody StudentEntity student){
            studentService.save(student);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("student/delete")
    @SaCheckPermission("student:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
            studentService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("student/update")
    @SaCheckPermission("student:update")
    @ResponseBody
    public DataResult update(@RequestBody StudentEntity student){
            studentService.updateById(student);
        return DataResult.success();
    }



}
